<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="checkbox" name="" id="box" />全选
    <ul>
        <li><input type="checkbox" name="" class="" id="ck" />张三</li>
        <li><input type="checkbox" name="" class="" id="ck" />李四</li>
        <li><input type="checkbox" name="" class="" id="ck" />麻子</li>
    </ul>
    <script>
        const box = document.querySelector('#box')
        const cks = document.querySelectorAll('#ck')
        box.addEventListener('click', function () {
            cks.forEach(item => item.checked = box.checked)
        })

        cks.forEach(item => {
            // console.log(item)
            item.addEventListener('click', function () {
                console.log(item.length === document.querySelectorAll('#ck:checked').length);
                if (cks.length === document.querySelectorAll('#ck:checked').length) {

                    box.checked = true
                } else {
                    box.checked = false
                }
            })
        })
    </script>
</body>

</html>